var authServiceId;

//授权选择  begin
//获取某个认证实体的授权信息（所有的，包括菜单和组件）
window.AUTH_INFO_URL = "platform/securityControlController/getauthinfo.json";
window.TARGET_TYPE = "1"; //修改后： 群组(1)，部门(2)，用户(3)，岗位(4)。
window.TARGET_ID = ""; // 目标ID
window.REFLASH_TYPE = ""; //要刷新的组件类型，可能是MENU,也可能是COMPONENT,如果为“”，则同时刷新二者
window.AUTH_DATA = eval("({menus:[],components:[]})");
window.MENU_ID = ""; // 记录当前选中的菜单ID， 下次展开的时候用
window.MENU_EVEL = ""; // 记录当前选中的菜单的层次，下次展开的时候用
window.TARGET_NAME = "";//目标NAME11
window.centerTreeId = "";//
var childLoadSuccess = false; //子页面iframe页面是否加载完毕标识，子页面加载完成后会更新为true

var authIndex = 0;//目标类型初次加载的
/**
 * 根据idField的值取得该行数据在datagrid中的rowIndex
 */
function getDataGridRowIndex(dataGridId, idFieldValue) {
	var dataGridObj = $('#' + dataGridId);
	return dataGridObj.datagrid('getRowIndex', idFieldValue);
}
var functionAction = true;
/**
 * 初始化tab
 */
function initTabContainer(dataGridHeight) {
	tabSelectedIndex = "0";
	$('#groupQueryText').searchbox({
		width : 200,
		searcher : function(value) {
			//"请输入查询内容"
			if (value == commonLang.optip.content21) {
				value = "";
			}
			searchRoleFun(value);
			//停止datagrid的编辑.
		},
		//"请输入查询内容"
		prompt : commonLang.optip.content21
	});
	//loadGroupList();

	$('#comprehensiveTabControl').tabs({
		onSelect : function(title, index) {
			if (index == 0) {
				tabSelectedIndex = "0";
				$('#groupQueryText').searchbox({
					width : 200,
					searcher : function(value) {
						//"请输入查询内容"
						if (value == commonLang.optip.content21) {
							value = "";
						}
						searchRoleFun(value);
						//停止datagrid的编辑.
					},
					//"请输入查询内容"
					prompt : commonLang.optip.content21
				});
				loadGroupList();
			}
			if (index == 1) {
				tabSelectedIndex = "1";
				$('#deptQueryText').searchbox({
					width : 200,
					searcher : function(value) {
						//"请输入查询内容"
						if (value == commonLang.optip.content21) {
							value = "";
						}
						var searchData = {
							search_text : value

						};
						var param = "multipleOrg=n&selectType=dept&deptKeyWord=" + value;
						ajaxRequest("POST", searchData, "platform/sysdept/sysDeptController/searchDept?_status=1", "json", "loadDeptTreeByData");
					},
					//"请输入查询内容"
					prompt : commonLang.optip.content21
				});
				loadDeptTree();
				$("#orgTree_dept").css("height", dataGridHeight - 84);
			}
			if (index == 2) {
				tabSelectedIndex = "2";
				$('#userQueryText').searchbox({
					width : 200,
					searcher : function(value) {
						//"请输入查询内容"
						if (value == commonLang.optip.content21) {
							value = "";
						}
						if (value.length == 0) {
							functionAction = true;
						} else {
							functionAction = false;
						}
						searchData();
					},
					//"请输入查询内容"
					prompt : commonLang.optip.content21
				});
				$("#dgUser").datagrid("options").url = "UserAuthSetController/getUsers.json?_status=1";
				$("#dgUser").datagrid('reload', {
					id : '',
					type : ''
				});

				$("#dgUser").datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
			}
			if (index == 3) {
				tabSelectedIndex = "3";
				$('#positionQueryText').searchbox({
					width : 200,
					searcher : function(value) {
						//"请输入查询内容"
						if (value == commonLang.optip.content21) {
							value = "";
						}
						searchPositionFun(value);
						//停止datagrid的编辑.
					},
					//"请输入查询内容"
					prompt : commonLang.optip.content21
				});
				loadPositionList();
			}
			if (index == 4) {
				tabSelectedIndex = "4";
				$('#positionQueryText').searchbox({
					width : 200,
					searcher : function(value) {
						//"请输入查询内容"
						if (value == commonLang.optip.content21) {
							value = "";
						}
						searchPositionFun(value);
						//停止datagrid的编辑.
					},
					//"请输入查询内容"
					prompt : commonLang.optip.content21
				});
				loadPositionList();
			}
		}
	});

	//$('#comprehensiveTabControl').tabs("select","角色");
	loadGroupList();
}
/**
 * 加载组织树
 */
function loadOrgTree(orgDatajson) {
	var orgData = eval(orgDatajson.orgDatajson);
	$('#orgTree_user').tree({
		//checkbox : true,
		lines : true,
		method : 'post',
		data : orgData,
		onCheck : function(node, checked) {

		},
		onBeforeExpand : function(node, param) {
			var beforeExpandUrl_ = 'platform/centralizedAuthorizationController/getDepts.json';
			var paraM = node.attributes.para;
			if (typeof (paraM) == 'undefined') {
				paraM = '';
			}
			$('#orgTree_user').tree('options').url = beforeExpandUrl_ + '?nodeType=' + node.attributes.nodeType + '&deptId=' + node.id + '&selectType=user&param=' + paraM;

		},
		onLoadSuccess : function(node, data) {
		}
	});
}

/**
 * 当用户点击部门节点时动态将部门人员及子部门人员自动添加至datagrid
 */
function displayAllUsers(data) {
	if (typeof (data) != 'undefined') {
		var users = data.allUsers;
		var checkBoxChecked = data.checked;
		if (checkBoxChecked == 'true') {
			$.each(users, function(x, user) {
				var insertIndex = getDataGridRowIndex("selectTargetDataGrid", user.userId);
				if (insertIndex == -1) {
					var selectionData = {
						"id" : user.userId,
						"name" : user.userName,
						type : "user",
						typeName : "用户"
					};
					$('#selectTargetDataGrid').datagrid('appendRow', selectionData);
					$('#selectTargetDataGrid').datagrid('checkRow', getDataGridRowIndex("selectTargetDataGrid", user.userId));
					//$('#selectUserTargetDataGrid').datagrid('selectRecord',user.userId);
				}
			});
		} else if (checkBoxChecked == 'false') {
			$.each(users, function(y, user) {
				var deleteIndex = getDataGridRowIndex("selectTargetDataGrid", user.userId);
				if (deleteIndex != -1) {
					$('#selectTargetDataGrid').datagrid('deleteRow', deleteIndex);
				}
			});
		}
	}
}
//展开树
function expand(root) {
	$('#orgTree_user').tree('expand', root.target);
}

/**
 * 加载组织树(初始化-页签(部门)信息)
 */
function loadDeptTree() {
	var orgTree_dept = $('#orgTree_dept');
	orgTree_dept.tree({
		lines : true,
		method : 'post',
		url : 'platform/sysdept/sysDeptController/getChildOrgDeptByIdAndOrgId.json?_status=1',
		onCheck : function(node, checked) {
		},
		onBeforeExpand : function(node, param) {
			if (node) {
				var beforeExpandUrl = 'platform/sysdept/sysDeptController/getChildOrgDeptByIdAndOrgId.json';
				orgTree_dept.tree('options').url = beforeExpandUrl + '?_status=1&type=' + node.attributes.type + '&id=' + node.id;
			}
		},
		loadFilter : function(data) {
			if (data.data) {
				return data.data;
			} else {
				return data;
			}
		}
	});
}
/**
 * 加载组织树
 */
function loadDeptTreeByData(orgDatajson) {
	var orgData = eval(orgDatajson.data);
	var orgTree_dept = $('#orgTree_dept');
	if (orgData.length == 1) {
		orgTree_dept.tree({
			//checkbox : true,
			lines : true,
			data : orgData,
			url : null,
			onCheck : function(node, checked) {

			},
			onBeforeExpand : function(node, param) {
			}
		});
	}
}

/**
 * 加载角色数据(初始化-页签(角色)信息)
 */
function loadGroupList() {
	$('#roleList').datagrid({
		fit : true,
		url : 'platform/UserAuthSetController/getUserRole',
		idField : 'id',
		singleSelect : true,
		nowrap : false,
		striped : true,
		autoRowHeight : false,
		checkOnSelect : true,
		pagination : true,
		pageSize : dataOptions.pageSize,
		pageList : dataOptions.pageList,
		remoteSort : false,
		fitColumns : true,
		columns : [ [ {
			field : 'ID',
			title : '角色ID',
			width : 25,
			hidden : 'true',
			fit : true
		}, {
			field : 'ROLE_NAME',
			title : commonLang.tip.partName,//角色名称
			width : 25,
			align : 'left',
			fit : true
		}, {
			field : 'ROLE_DESC',
			title : commonLang.tip.partDescribe,//角色描述
			width : 50,
			align : 'left',
			sortable : false,
			fit : true
		} ] ],
		onLoadSuccess : function(data) {
			if (data.rows.length > 0) {
			}
			$("#roleList").datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
			if(firstLoadFlag && parent.location.pathname.indexOf('NavigationOfCreateSubOrg.jsp')>0){
				firstLoadFlag = false;
				setTimeout(function(){
					$("#roleList").datagrid("selectRow",0);
					setTargetId();
				},500);
			}
			},
		onClickRow : function(rowIndex, rowData) {
			setTargetId();
		},
		toolbar : '#roleToolbar'
	});
	$("#roleList").datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
}
var setTargetId;
var firstLoadFlag=true;
/**
 * 初始化-页签(岗位)信息
 */
function loadPositionList() {
	$('#positionList').datagrid({
		fit : true,
		url : 'platform/centralizedAuthorizationController/getSysPosition.json?type=position',
		idField : 'id',
		nowrap : false,
		striped : true,
		singleSelect : true,
		autoRowHeight : false,
		checkOnSelect : true,
		remoteSort : false,
		pagination : true,
		pageSize : dataOptions.pageSize,
		pageList : dataOptions.pageList,
		fitColumns : true,
		columns : [ [ {
			field : 'id',
			title : '岗位ID',
			width : 25,
			hidden : 'true',
			fit : true
		}, {
			field : 'positionName',
			title : commonLang.tip.postName,
			width : 25,
			align : 'left',
			fit : true
		}, {
			field : 'positionDesc',
			title : commonLang.tip.postDescribe,
			width : 80,
			align : 'left',
			sortable : false,
			fit : true
		} ] ],
		onLoadSuccess : function(data) {
			if (data.rows.length > 0) {

			}
		},
		toolbar : '#positionToolbar'
	});
}
//查询
function searchRoleFun(queryKeyWord) {
	if (queryKeyWord == null) {
		//"操作提示", "请输入查询条件！"
		$.messager.alert(commonLang.tip.operateAlert, commonLang.optip.content5, "warning");
		return;
	}
	var queryParams = $('#roleList').datagrid('options').queryParams;
	queryParams.roleQueryKey = queryKeyWord;
	$('#roleList').datagrid('options').queryParams = queryParams;
	$("#roleList").datagrid('load');
	$("#roleList").datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
}

//查询
function searchPositionFun(queryKeyWord) {
	if (queryKeyWord == null) {
		//"操作提示", "请输入查询条件！"
		$.messager.alert(commonLang.tip.operateAlert, commonLang.optip.content5, "warning");
		return;
	}
	var queryParams = $('#positionList').datagrid('options').queryParams;
	queryParams.positionKeyWord = queryKeyWord;
	$('#positionList').datagrid('options').queryParams = queryParams;
	$("#positionList").datagrid('load');
}
//查询
function searchGroupFun(queryKeyWord) {
	if (queryKeyWord == null) {
		//"操作提示", "请输入查询条件！"
		$.messager.alert(commonLang.tip.operateAlert, commonLang.optip.content5, "warning");
		return;
	}
	var queryParams = $('#groupList').datagrid('options').queryParams;
	queryParams.queryKeyWord = queryKeyWord;
	$('#groupList').datagrid('options').queryParams = queryParams;
	$("#groupList").datagrid('load');
}

/**
 * 用户查询回调函数
 * @param queryResult
 */
function loadUserTreeQueryResult(queryResult) {
	var queryJson = eval(queryResult);
	$('#orgTree_user').tree("loadData", queryJson);
	if (functionAction == false) {
		$('#orgTree_user').tree('expandAll');
	}
}

/**
 * 部门查询回调函数
 * @param queryResult
 */
function loadDeptTreeQueryResult(queryResult) {
	var queryJson = eval(queryResult);
	$('#orgTree_dept').tree("loadData", queryJson);
	$('#orgTree_dept').tree('expandAll');
}

/*当前类型start 角色(1)，部门(2)，用户(3)，岗位(4)*/
$(function() {
	$(".tabs").find("li").click(function() {
		window.TARGET_TYPE = "1"; // 根据刚加载的位置，默认为“角色”
		window.TARGET_ID = "";
		var targetName = $(this).text();
		switch (targetName) {
		case commonLang.tip.role:
			window.TARGET_TYPE = "1";
			window.loadAuthInfoData();
			break;
		case commonLang.tip.dept:
			window.TARGET_TYPE = "2";
			window.loadAuthInfoData();
			break;
		case commonLang.tip.user:
			window.TARGET_TYPE = "3";
			window.loadAuthInfoData();
			break;
		case commonLang.tip.post:
			window.TARGET_TYPE = "4";
			window.loadAuthInfoData();
			break;
		default:
			window.TARGET_TYPE = "1";
		}
	});
});
/*当前类型end*/

/*当前ID 角色(1)，部门(2)，用户(3)，岗位(4)*/
$(function() {
	function settargetId() {
		var selections;
		switch (window.TARGET_TYPE) {
		case "1"://角色
			selections = $('#roleList').datagrid('getSelections');
			if (!selections || !selections[0])
				break;
			window.TARGET_ID = selections[0].ID;
			window.TARGET_NAME = selections[0].ROLE_NAME;
			window.loadAuthInfoData();
			break;
		case "2"://部门
			selections = $('#orgTree_dept').tree('getSelected');
			if (!selections)
				break;
			window.TARGET_ID = selections.id;
			window.loadAuthInfoData();
			break;
		case "3"://用户
			selections = $('#dgUser').datagrid('getSelections');
			if (!selections || !selections[0])
				break;
			window.TARGET_ID = selections[0].ID;
			window.loadAuthInfoData();
			break;
		case "4"://岗位
			selections = $('#positionList').datagrid('getSelections');
			if (!selections || !selections[0])
				break;
			window.TARGET_ID = selections[0].id;
			window.loadAuthInfoData();
			break;
		default:
			selections = null;
		}
		$(".searchbox-text").val("");
	};
	setTargetId = settargetId;
	/*$('#roleList').datagrid({
		onClickRow : function(rowIndex, rowData) {
			settargetId();
		}
	});*/
	$('#dgUser').datagrid({
		onClickRow : function(rowIndex, rowData) {
			settargetId();
		}
	});
	$('#orgTree_dept').tree({
		onSelect : function() {
			settargetId();
		}
	});
	$('#positionList').datagrid({
		onClickRow : function(rowIndex, rowData) {
			settargetId();
		}
	});
});
/*当前ID end*/

/**
 * 展开部门选择对话框
 */
function authSelectDept() {
    var deptSelector = new CommonSelector("dept", "deptSelectCommonDialog", "authSelectedDeptId", null, null, null, null, null, null, null, 600, 400);
	deptSelector.init(false, "selectDeptDialogCallBack", 'n');
}
//部门选择回调
function selectDeptDialogCallBack(data) {
	$("#authSelectedDeptId").val(data[0].deptId);
	searchDeptData();
}
/**
 * 确定后保存选择的部门ID到页面指定位置
 * @param deptId
 */
function saveSelectedDeptId(deptId) {
	$("#authSelectedDeptId").val(deptId);
	searchDeptData();
	$("#authSelectDeptDialog").dialog('close');
}

/**
 * 用户tab输入查询内容后查询数据
 * @returns
 */
function searchData() {
	$("#dgUser").datagrid("options").url = "UserAuthSetController/getUsers.json?_status=1";
	var queryKeyWord = $('#userQueryText').searchbox("getValue");
	var searchData = {
		search_LOGIN_NAME : queryKeyWord,
		search_USER_NAME : queryKeyWord
	};
	$('#dgUser').datagrid('load', searchData);
	$("#dgUser").datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
}

function searchDeptData() {
	$("#dgUser").datagrid("options").url = "UserAuthSetController/getUsers.json?_status=1";
	var depeId = $("#authSelectedDeptId").val();
	var type = "";
	if (depeId != null && depeId.length > 0) {
		type = "dept";
	}
	var queryKeyWord = $('#userQueryText').searchbox("getValue");
	var searchData = {
		search_LOGIN_NAME : queryKeyWord
	};
	searchData.id = depeId;
	searchData.type = type;
	$('#dgUser').datagrid('load', searchData);
	$("#dgUser").datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
}
/*当前ID end*/

//点击，选中不同权限主体时，激发的事件:所选维度类型发生改变
window.loadAuthInfoData = function() {
	if (childLoadSuccess) {
		if (authServiceId == "LANTOP_AUTH_SERVER_FUNC") {
			document.getElementById('mainIframe').contentWindow.targetType = TARGET_TYPE; //对iframe页面所选维度类型更新
			document.getElementById('mainIframe').contentWindow.targetId = TARGET_ID; //对iframe页面所选维度ID更新
			document.getElementById('mainIframe').contentWindow.resourceDatagridLoad(); //重新加载资源列表
		} else if (authServiceId == "LANTOP_AUTH_SERVER_USERSET") {
			document.getElementById('mainIframe').contentWindow.targetType = TARGET_TYPE; //对iframe页面所选维度类型更新
			document.getElementById('mainIframe').contentWindow.targetId = TARGET_ID; //对iframe页面所选维度ID更新
			document.getElementById('mainIframe').contentWindow.targetName = TARGET_NAME;
			document.getElementById('mainIframe').contentWindow.userDatagridLoad(); //重新加载资源列表
		}
	}
};
//授权选择 end

/**
 * 授权服务行被选中事件:跳转服务对应的权限设置页面
 */
function serviceOnSelect(rowIndex, rowData) {
	document.getElementById("mainIframe").src = "platform/UserAuthSetController/toAuthConfigJsp?serviceId=" + authServiceId;
}

/**
 * 授权服务数据加载完成事件
 * @param data
 */
function serviceOnLoadSuccess(data) {
	$("#serviceDatagrid").datagrid("selectRow", 0);
}

/**
 * 展开部门选择对话框
 */
function authSelectDept() {
	var deptSelector = new CommonSelector("dept", "deptSelectCommonDialog", "authSelectedDeptId", null, null, null, null, null, null, null, 600, 400);
	deptSelector.init(false, "selectDeptDialogCallBack", 'n');
}

/**
 * 展开部门选择对话框
 */
function authSelectDept() {
	var deptSelector = new CommonSelector("dept", "deptSelectCommonDialog", "authSelectedDeptId", null, null, null, null, null, null, null, 600, 400);
	deptSelector.init(false, "selectDeptDialogCallBack", 'n');
}
//部门选择回调
function selectDeptDialogCallBack(data) {
	$("#authSelectedDeptId").val(data[0].deptId);
	searchDeptData();
}
/**
 * 确定后保存选择的部门ID到页面指定位置
 * @param deptId
 */
function saveSelectedDeptId(deptId) {
	$("#authSelectedDeptId").val(deptId);
	searchDeptData();
	$("#authSelectDeptDialog").dialog('close');
}

function maskDo() {
	MaskUtil.mask();
}

function unMaskDo() {
	MaskUtil.unmask();
}

/**
 * 新增条件
 */
function addQualification_open(checkedRows, targetType, userId, authServceId) {
	var isEq = true;
	var nodeIds = "";
	var nodeNames = "";
	for ( var i = 0; i < checkedRows.length; i++) {
		if (i > 0) {
			if (checkedRows[i].PARENT_ID != checkedRows[i - 1].PARENT_ID) {
				isEq = false;
				break;
			}
		}
		//节点为数据节点
		if (checkedRows[i].ARCHIVE_CLASS_NODE_TYPE == 2) {
			nodeIds += checkedRows[i].ID + ",";
			nodeNames += checkedRows[i].ARCHIVE_CLASS_NODE_NAME + ",";
		}
	}
	if (isEq) {
		if (nodeIds != "") {
			nodeIds = nodeIds.substring(0, nodeIds.length - 1);
			nodeNames = nodeNames.substring(0, nodeNames.length - 1);
			var dialogId = "addQualificationDialogId";
			//"节点名称："
			var usd = new CommonDialog(dialogId, "800", "400", "platform/UserAuthSetController/toAddQualificationJsp?dialogId=" + dialogId + "&nodeIds=" + nodeIds + "&targetType=" + targetType + "&targetId=" + userId+ "&authServiceId=" + authServceId + "&nodeNames=" + encodeURI(nodeNames) , commonLang.tip.nodename + checkedRows[0].ARCHIVE_CLASS_NODE_NAME, false, true, false, false, true);
			usd.show();
		} else {
			//'提示', '请选择数据节点！'
			$.messager.alert(commonLang.tip.alert, commonLang.optip.del.selectNode, 'warning');
		}
	} else {
		//'提示', '所选节点不在同一模板下，不允许执行【新增条件】设置！'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.content6, 'warning');
	}
}

/**
 * 编辑条件
 */
function editQualification_open(checkedRows, targetType, userId, authServceId) {
	if (checkedRows.length < 1) {
		//'提示', '请选择数据节点！'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.del.selectNode, 'warning');
	} else if (checkedRows.length > 1) {
		//'提示', '只能选择一条记录'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.content7, 'warning');
	} else {
		//节点为数据节点
		if (checkedRows[0].ARCHIVE_CLASS_NODE_TYPE != 2) {
			//'提示', '请选择数据节点！'
			$.messager.alert(commonLang.tip.alert, commonLang.optip.del.selectNode, 'warning');
		} else {
			var dialogId = "editQualificationDialogId";
			var usd = new CommonDialog(dialogId, "800", "400", "platform/UserAuthSetController/toEditQualificationJsp?dialogId=" + dialogId + "&nodeId=" + checkedRows[0].ID + "&targetType=" + targetType + "&targetId="+ userId  + "&authServiceId=" + authServceId  + "&nodeName="
					+ encodeURI(encodeURI(checkedRows[0].ARCHIVE_CLASS_NODE_NAME)), commonLang.tip.nodename + checkedRows[0].ARCHIVE_CLASS_NODE_NAME, false, true, false, false, true);
			usd.show();
		}
	}
}

/**
 * 删除条件
 */
function delQualification_open(checkedRows, targetType, userId, authServceId) {
	if (checkedRows.length < 1) {
		//'提示', '请选择数据节点！'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.del.selectNode, 'warning');
	} else if (checkedRows.length > 1) {
		//'提示', '一次只允许删除一个节点所定义的条件！'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.content8, 'warning');
	} else {
		//节点为数据节点
		if (checkedRows[0].ARCHIVE_CLASS_NODE_TYPE != 2) {
			//'提示', '请选择数据节点！'
			$.messager.alert(commonLang.tip.alert, commonLang.optip.del.selectNode, 'warning');
		} else {
			var dialogId = "delQualificationDialogId";
			var usd = new CommonDialog(dialogId, "800", "400", "platform/UserAuthSetController/toDelQualificationJsp?dialogId=" + dialogId + "&nodeId=" + checkedRows[0].ID + "&targetId=" + userId + "&targetType=" + targetType+ "&authServiceId=" + authServceId + "&nodeName="
					+ checkedRows[0].ARCHIVE_CLASS_NODE_NAME, commonLang.tip.nodename + checkedRows[0].ARCHIVE_CLASS_NODE_NAME, false, true, false, false, true);
			usd.show();
		}
	}
}

/**
 * 条件设置成后处理
 */
function savequalificationAfter() {
	parent.parent.parent.$.messager.show({
		//'提示',"所选节点条件设置成功！"
		title : commonLang.tip.alert,
		msg : commonLang.optip.save.nodeConditionSet
	});
}

/**
 * 批量操作权限设置
 */
function batchOperateAuthSet_open(checkedRows, targetType, userId, authServceId) {
	var nodeIds = "";
	var nodeNames = "";
	var cbbAuthResourceId = "";
	var actionType = "";
	var operateAuth = "";
	var errMsg = "";
	for ( var i = 0; i < checkedRows.length; i++) {
		//节点为数据节点
		if (checkedRows[i].ARCHIVE_CLASS_NODE_TYPE == 2) {
			nodeIds += checkedRows[i].ID + ",";
			nodeNames += checkedRows[i].ARCHIVE_CLASS_NODE_NAME + ",";
			if (null == checkedRows[i].CBB_AUTH_RESOURCE_ID || "" == checkedRows[i].CBB_AUTH_RESOURCE_ID) {
				errMsg = checkedRows[i].ARCHIVE_CLASS_NODE_NAME + "未设置操作权限，请先设置操作权限！";
				break;
			}
			cbbAuthResourceId += checkedRows[i].CBB_AUTH_RESOURCE_ID + ",";
			actionType += checkedRows[i].ACTION_TYPE + ",";
			operateAuth += checkedRows[i].OPERATE_AUTH + ",";
		}
	}
	if (errMsg != "") {
		$.messager.alert('提示', errMsg, 'warning');
		return;
	}
	if (nodeIds != "") {
		var operateCount = 0;
		//验证是否已设置操作权限，批量设置只能针对没有设置操作权限的数据
		$.ajax({
			async : false,
			url : 'platform/UserAuthSetController/hasOperateAuthSet',
			data : {
				cbbAuthResourceIds : cbbAuthResourceId
			},
			type : 'post',
			dataType : 'json',
			success : function(result) {
				operateCount = result.count;
			}
		});

		if (operateCount > 0) {
			//'提示', '所选节点已设置操作权限，不允许执行批量设置操作！'
			$.messager.alert(commonLang.tip.alert, commonLang.optip.content9, 'warning');
			return;
		}
		nodeIds = nodeIds.substring(0, nodeIds.length - 1);
		nodeNames = nodeNames.substring(0, nodeNames.length - 1);
		var dialogId = "batchOperateAuthSetDialogId";
		//"批量操作权限设置"
		var usd = new CommonDialog(dialogId, "800", "400", "platform/UserAuthSetController/toBatchOperateAuthSetJsp?" + "dialogId=" + dialogId + "&cbbAuthResourceId=" + cbbAuthResourceId + "&targetType=" + targetType + "&targetId=" + userId + "&authServiceId=" + authServceId
				+ "&resCode=" + nodeIds + "&resName=" + encodeURI(encodeURI(nodeNames)) + "&actionType=" + actionType + "&operateAuth=" + operateAuth, commonLang.optip.content10, false, true, false, false, true);
		usd.show();
	} else {
		//'提示', '请选择条目！'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.add.selectEntry, 'warning');
	}
}

/**
 * 批量操作权限设置
 */
function batchOperateAuthSet_open_new(checkedRows, targetType, userId, authServceId) {
	var nodeIds = "";
	var nodeNames = "";
	var cbbAuthResourceId = "";
	var actionType = "";
	var operateAuth = "";
	for ( var i = 0; i < checkedRows.length; i++) {
		//节点为数据节点
		nodeIds += checkedRows[i].ID + ",";
		nodeNames += checkedRows[i].ARCHIVE_CLASS_NODE_NAME + ",";
		cbbAuthResourceId += checkedRows[i].CBB_AUTH_RESOURCE_ID + ",";
		actionType += checkedRows[i].ACTION_TYPE + ",";
		operateAuth += checkedRows[i].OPERATE_AUTH + ",";
	}
	if (nodeIds != "") {
		nodeIds = nodeIds.substring(0, nodeIds.length - 1);
		nodeNames = nodeNames.substring(0, nodeNames.length - 1);
		var dialogId = "batchOperateAuthSetDialogId";
		var usd = new CommonDialog(dialogId, "800", "400", "platform/UserAuthSetController/toBatchOperateAuthSetJsp?"+ "sysId=" + sysId + "&dialogId=" + dialogId + "&cbbAuthResourceId=" + cbbAuthResourceId + "&targetType=" + targetType + "&targetId=" + userId + "&authServiceId=" + authServceId
				+ "&resCode=" + nodeIds + "&resName=" + encodeURI(encodeURI(nodeNames)) + "&actionType=" + actionType + "&operateAuth=" + operateAuth, commonLang.optip.content10, false, true, false, false, true);
		usd.show();
	} else {
		//'提示', '请选择条目！'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.add.selectEntry, 'warning');
	}
}

/**
 * 条目权限设置
 */
function entryAuthSet_open(checkedRows, targetType, userId, authServceId) {
	var isEq = true;
	var nodeIds = "";
	for ( var i = 0; i < checkedRows.length; i++) {
		if (i > 0) {
			if (checkedRows[i].PARENT_ID != checkedRows[i - 1].PARENT_ID) {
				isEq = false;
				break;
			}
		}
		//节点为数据节点
		if (checkedRows[i].ARCHIVE_CLASS_NODE_TYPE == 2) {
			nodeIds += checkedRows[i].ID + ",";
		}
	}
	if (isEq) {
		if (nodeIds != "") {
			nodeIds = nodeIds.substring(0, nodeIds.length - 1);
			var dialogId = "entryAuthSetDialogId";
			var usd = new CommonDialog(dialogId, "800", "400", "platform/UserAuthSetController/toEntryAuthSetJsp?" + "dialogId=" + dialogId + "&nodeIds=" + nodeIds + "&targetId=" + userId + "&targetType=" + targetType, commonLang.optip.content14, false, true, false, false, true);
			usd.show();
		} else {
			//'提示', '请选择条目！'
			$.messager.alert(commonLang.tip.alert, commonLang.optip.add.selectEntry, 'warning');
		}
	} else {
		//'提示', '所选节点不在同一模板下，不允许执行【条目权限设置】！'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.content11, 'warning');
	}
}

/**
 * 条件复制
 */
function copyQualification_open(checkedRows, targetType, userId) {
	if (checkedRows.length > 0) {
		if (checkedRows.length > 1) {
			//'提示', '只能选择一条记录！'
			$.messager.alert(commonLang.tip.alert, commonLang.optip.content7, 'warning');
			return;
		}
		var dialogId = "copyQualificationDialogId";
		//"条件复制"
		var usd = new CommonDialog(dialogId, "800", "400", "platform/UserAuthSetController/toCopyQualificationJsp?" + "dialogId=" + dialogId + "&targetType=" + targetType + "&targetId=" + userId + "&copyNodeId=" + checkedRows[0].ID, commonLang.optip.content13, false, true, false, false, true);
		usd.show();
	} else {
		//'提示', '请选择模板！'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.content12, 'warning');
	}
}

/**
 * 权限复制
 */
function copyAuth_open(userRow, targetType, userId) {
	if (null != userRow) {
		if (userId != null && userId != "") {
			var dialogId = "copyAuthDialogId";
			var usd = new CommonDialog(dialogId, "800", "400", "platform/UserAuthSetController/toCopyAuthJsp?" + "dialogId=" + dialogId + "&targetType=" + targetType + "&targetId=" + userId, commonLang.optip.content20, false, true, false, false, true);
			usd.show();
		} else {
			//'提示', '请选择用户！'
			$.messager.alert(commonLang.tip.alert, commonLang.optip.add.selectUser, 'warning');
		}
	} else {
		//'提示', '请选择用户！'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.add.selectUser, 'warning');
	}
}

/**
 * 复制完成，提示并关闭弹出页
 * @param dialogId
 * @param flag
 */
function copyAfter(dialogId, flag) {
	$('#' + dialogId).dialog('close');
	if (flag == 0) {
		parent.parent.parent.$.messager.show({
			title : '提示',
			//"操作成功！"
			msg : commonLang.optip.content15
		});
	} else {
		parent.parent.parent.$.messager.show({
			title : '提示',
			//"操作成功！"
			msg : commonLang.optip.content15
		});
	}
}

/**
 * 打开操作权限设置页面
 * @param rowId
 */
function operateRoleSet_open(archiveClassNodeName, relTargetId, relTargetNames, cbbAuthResourceId, targetType, userId, authServiceId, resCode, resName, actionType, operateAuth) {
	if (null == cbbAuthResourceId || cbbAuthResourceId == "null" || cbbAuthResourceId == "") {
		//'提示', '请先设置操作权限！'
		$.messager.alert(commonLang.tip.alert, commonLang.optip.content16, 'warning');
		return;
	}
	var dialogId = "operateRoleSetDialogId";
	var usd = new CommonDialog(dialogId, "800", "400", "platform/UserAuthSetController/toOpeateAuthSetJsp?" + "dialogId=" + dialogId + "&relTargetId=" + relTargetId + "&relTargetNames=" + encodeURI(encodeURI(relTargetNames)) + "&cbbAuthResourceId=" + cbbAuthResourceId
			+ "&targetType=" + targetType + "&targetId=" + userId + "&authServiceId=" + authServiceId + "&resCode=" + resCode + "&resName=" + encodeURI(encodeURI(resName)) + "&actionType=" + actionType + "&operateAuth=" + operateAuth, commonLang.tip.nodename + archiveClassNodeName, false, true, false, false, true);
	usd.show();
}

/**
 * 批量设置操作权限保存后处理
 * @param flag
 */
function batchOperateAuthSetSaveAfter(flag) {
	if (flag == "0") {
		parent.parent.parent.$.messager.show({
			title : '提示',
			//"保存操作权限成功！"
			msg : commonLang.optip.content17
		});
	} else {
		parent.parent.parent.$.messager.show({
			title : '提示',
			//"保存操作权限失败！"
			msg : commonLang.optip.content18
		});
	}
}

/**
 * 设置操作权限保存成功后处理
 */
function saveOperateAuthSetAfter() {
	parent.parent.parent.$.messager.show({
		title : '提示',
		msg : commonLang.optip.content17
	});
}

/**
 * 操作角色设置窗口关闭后调用方法，刷新操作角色列表
 */
function operateRoleSetAfter(dialogId) {
	if (dialogId != null && dialogId != "") {
		$('#' + dialogId).dialog('close');
	}
	document.getElementById('mainIframe').contentWindow.operateRoleSetAfter(dialogId);//父页面调用子页面表格刷新方法
}

/**
 * 2018-12-14
 * add by heps
 * 打开编辑条件页
 */
function openEditQualification(nodeType,rowDataID,relTargetNames, targetType, userId, authServceId) {
		var dialogId = "editQualificationDialogId";
		var usd = new CommonDialog(dialogId, "800", "400", "platform/UserAuthSetController/toEditQualificationJsp?dialogId=" + dialogId + "&nodeId=" + rowDataID + "&targetType=" + targetType + "&targetId=" + userId + "&nodeName="
				+ encodeURI(encodeURI(relTargetNames)) + "&authServiceId=" + authServceId, commonLang.tip.nodename + relTargetNames, false, true, false, false, true);
		usd.show();
}